﻿using System;
using System.IO;
using System.Linq;
using System.Reflection;

using Xc.Views.Core.Properties;

namespace Xc.Views.Core
{
    /// <summary>
    /// 启抽象类
    /// </summary>
    public abstract class StartupCore: StartupBase
    {
        public StartupCore(string applicationName, string applicationVersion) : base(applicationName, applicationVersion)
        {

        }

        /// <summary>
        /// 启抽象类
        /// </summary>
        public StartupCore()
        {

        }

        /// <summary>
        /// 数据库文件夹
        /// </summary>
        public string ApplicationDataFolder
        {
            get
            {
                var attr = (BootAttribute)this.GetType().GetCustomAttributes(typeof(BootAttribute)).FirstOrDefault();
                if (attr != null)
                {
                    this.ApplicationName = attr.ApplicationName;
                    this.ApplicationVersion = attr.ApplicationVersion;
                }
                if (this.ApplicationName == null)
                {
                    throw new ArgumentNullException(TextResource.please_add_applicationName);
                }
                var path1 = Path.Combine(Environment.GetFolderPath(StoreFolderName),"ProgramData", ApplicationName, ApplicationVersion);
                if (!Directory.Exists(path1))
                {
                    Directory.CreateDirectory(path1);
                }
                return path1;
            }
        }
        /// <summary>
        /// 配置文件的文件位置
        /// </summary>
        public string ApplicationSettingFileName => Path.Combine(ApplicationDataFolder,AppSettingName);
        /// <summary>
        /// 连接字符串
        /// </summary>
        public virtual string ConnectionString 
        {
            get
            {
                var file = Path.Combine(ApplicationDataFolder, "database.sqlite");
               return $"DataSource={file}";
            }
        }
    }
}
